package server.controller.goodController;

import base.BaseValue;
import server.entity.Good;
import server.model.factory.ModelFactory;
import server.util.InfoUtils.Info;
import server.util.MyUtils;
import server.util.ResponseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/addGood")
@MultipartConfig(maxFileSize = 50000000)
public class AddGoodServlet extends HttpServlet {
    private static final long serialVersionUID = 2141638604440676074L;

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer storeId = ModelFactory.getStoreModel().getStoreId(req);
        Good good = MyUtils.convertRequest2Bean(req, Good.class, BaseValue.picLoad, "good-pic-");
        good.setStoreId(storeId);
        Info info = ModelFactory.getGoodModel().addGood(good);
        ResponseUtil.responseMessage(resp, info);
    }
}